#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2021, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: 0026.py
@time: 2021/9/27 16:27
@desc: https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/submissions/
'''
class Solution:
    def reverseWords(self, s: str) -> str:
        sl = s.split()
        n = len(sl)
        i, j = 0, n-1
        while i<j:
            t = sl[i]
            sl[i] = sl[j]
            sl[j] = t
            i +=1
            j -= 1
        res = ' '.join(sl)
        return res

if __name__ == '__main__':
    inp = "  hello world!  "
    res = Solution().reverseWords(inp)
    print(res)